/*
 * @lc app=leetcode.cn id=232 lang=cpp
 *
 * [232] 用栈实现队列
 */

#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <stack>
using namespace std;

// @lc code=start
class MyQueue {
public:
    // 定义两个栈，用来模拟队列操作
    stack<int> stack1;
    stack<int> stack2;
    
    MyQueue() {
        
    }
    
    void push(int x) {
        stack1.push(x);
    }
    
    int pop() {
        // 如果 stack2 为空，则将 stack1 中的元素依次存入 stack2
        if (stack2.empty()) {
            while (!stack1.empty()) {
                int tmp = stack1.top();
                stack1.pop();
                stack2.push(tmp);
            }
        }

        int result = stack2.top();
        stack2.pop();
        return result;
    }
    
    int peek() {
        // 如果 stack2 为空，则将 stack1 中的元素依次存入 stack2
        if (stack2.empty()) {
            while (!stack1.empty()) {
                int tmp = stack1.top();
                stack1.pop();
                stack2.push(tmp);
            }
        }

        return stack2.top();
    }
    
    bool empty() {
        return stack1.empty() && stack2.empty();
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
// @lc code=end

